package com.songlanyun.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import com.songlanyun.common.drive.IntegerEnum;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;


/**
 * 优惠券相关枚举
 */
public class CouponConstant {


    public final static Map<CouponConstant.ActivityCouponType,Integer> ADAPT_ACTIVITY  = new HashMap<>();
    static {
        ADAPT_ACTIVITY.put(CouponConstant.ActivityCouponType.FIRST_ORDER,1);
        ADAPT_ACTIVITY.put(CouponConstant.ActivityCouponType.SECKILL,2);
        ADAPT_ACTIVITY.put(CouponConstant.ActivityCouponType.GROUP_BUY,4);
    }



    /**
     * 活动类型
     * FIRSTORDER：首单
     * SECKILL：秒杀
     * GROUPBUY：拼团
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public static enum ActivityCouponType implements IntegerEnum<String> {

        FIRST_ORDER("FIRSTORDER", "首单"),

        SECKILL("SECKILL", "秒杀"),

        GROUP_BUY("GROUPBUY", "拼团"),

        ;

        @EnumValue
        @JsonValue
        private String code;

        private String msg;

        ActivityCouponType(String code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public void setCode(String code) {
            this.code = code;
        }

        @Override
        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        @Override
        public String getCode() {
            return code;
        }

        @JsonCreator
        public static ActivityCouponType getByCode(String code) {
            for (ActivityCouponType value : ActivityCouponType.values()) {
                if (Objects.equals(code, value.getCode())) {
                    return value;
                }
            }
            return null;
        }
    }

    /**
     * 优惠券范围
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public static enum CouponMode implements IntegerEnum<Integer> {
        //平台券
        PLATFORM(0, "平台券"),
        SHOP(1, "店铺券"),
        ;


        @EnumValue
        @JsonValue
        private Integer code;

        private String msg;

        CouponMode(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        @Override
        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @JsonCreator
        public static CouponConstant.CouponMode getByCode(int code) {
            for (CouponConstant.CouponMode value : CouponConstant.CouponMode.values()) {
                if (Objects.equals(code, value.getCode())) {
                    return value;
                }
            }
            return null;
        }
    }

    /**
     * 优惠券特征
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public static enum CouponTrait implements IntegerEnum<Integer> {
        //普通券
        GENERAL(0, "普通券"),
        NEW_PEOPLE(1, "新人券"),
        ;


        @EnumValue
        @JsonValue
        private Integer code;

        private String msg;

        CouponTrait(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        @Override
        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @JsonCreator
        public static CouponConstant.CouponTrait getByCode(int code) {
            for (CouponConstant.CouponTrait value : CouponConstant.CouponTrait.values()) {
                if (Objects.equals(code, value.getCode())) {
                    return value;
                }
            }
            return null;
        }
    }

    /**
     * 优惠券状态 0已终止，1待发布，2已发布
     *  0: 已终止
     *  1：待发布
     *  2：已发布
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public static enum CouponStatus implements IntegerEnum<Integer> {
        //已终止
        STOP(0, "已终止"),
        WAIT_RELEASE(1, "待发布"),
        RELEASED(2, "已发布"),
        ;
        @EnumValue
        @JsonValue
        private Integer code;

        private String msg;

        CouponStatus(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        @Override
        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @JsonCreator
        public static CouponConstant.CouponStatus getByCode(int code) {
            for (CouponConstant.CouponStatus value : CouponConstant.CouponStatus.values()) {
                if (Objects.equals(code, value.getCode())) {
                    return value;
                }
            }
            return null;
        }
    }

    /**
     * 优惠券状态 0已终止，1待发布，2已发布,3正常,4已完成
     *  0: 已终止
     *  1：待发布
     *  2：已发布
     *  3: 正常
     *  4：已完成
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public static enum UseStatus implements IntegerEnum<Integer> {
        //已终止
        STOP(0, "已终止"),
        WAIT_RELEASE(1, "待发布"),
        RELEASED(2, "已发布"),
        NORMAL(3, "正常"),
        COMPLETE(4, "已完成"),
        ;
        @EnumValue
        @JsonValue
        private Integer code;

        private String msg;

        UseStatus(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        @Override
        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @JsonCreator
        public static CouponConstant.UseStatus getByCode(int code) {
            for (CouponConstant.UseStatus value : CouponConstant.UseStatus.values()) {
                if (Objects.equals(code, value.getCode())) {
                    return value;
                }
            }
            return null;
        }
    }

    /**
     * 优惠券类型
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public static enum CouponType implements IntegerEnum<Integer> {
        //满减券
        FULL_REDUCE(0, "满减券"),
        ;


        @EnumValue
        @JsonValue
        private Integer code;

        private String msg;

        CouponType(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        @Override
        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @JsonCreator
        public static CouponConstant.CouponType getByCode(int code) {
            for (CouponConstant.CouponType value : CouponConstant.CouponType.values()) {
                if (Objects.equals(code, value.getCode())) {
                    return value;
                }
            }
            return null;
        }
    }

}
